#include <iostream>
#define _USE_MATH_DEFINES
#include <cmath>
using namespace std;

class Polar;

class Decart
{
private:
    double x;
    double y;
public:
    Decart()
    {
        x = 0;
        y = 0;
    }

    Decart(double x_, double y_) :x(x_), y(y_) {}

    Decart(const Decart& point) :x(point.x), y(point.y) {}

    Decart(Polar& point);

    void setCord(double x_, double y_);

    void setX(double x_);

    void setY(double y_);

    void setPolarCord(double r, double p);

    pair<double, double> getCord();

    double getX();

    double getY();

    Polar getPolarCord();

    void print();
};

class Polar
{
private:
    double r;
    double p;
public:
    Polar()
    {
        r = 0;
        p = 0;
    }

    Polar(double r_, double p_);

    Polar(const Polar& point):r(point.r), p(point.p){}

    Polar(Decart& point);

    void setCord(double r_, double p_);

    void setR(double r_);

    void setP(double p_);

    void setDecartCord(double x, double y);

    pair<double, double> getCord();

    double getR();

    double getP();

    Decart getDecartCord();

    void print();
};

Polar::Polar(double r_, double p_)
{
    try
    {
        if(r_ < 0 || p_ > 2*M_PI || p_ < 0) throw "Wrong radius or angle";
        r = r_;
        p = p_;
    }
    catch(const char* str)
    {
        r = 0;
        p = 0;
        cout << str << endl;
    }
}

Polar::Polar(Decart& point)
{
    Polar tmp = point.getPolarCord();
    r = tmp.r;
    p = tmp.p;
}

void Polar::setCord(double r_, double p_)
{
    try
    {
        if(r_ < 0 || p_ > 2*M_PI || p_ < 0) throw "Wrong radius or angle";
        r = r_;
        p = p_;
    }
    catch(const char* str)
    {
        cout << str << endl;
    }
}

void Polar::setR(double r_)
{
    try
    {
        if(r_ < 0) throw "Wrong radius";
        r = r_;
    }
    catch(const char* str)
    {
        cout << str << endl;
    }
}

void Polar::setP(double p_)
{
    try
    {
        if(p_ > 2*M_PI || p_ < 0) throw "Wrong angle";
        p = p_;
    }
    catch(const char* str)
    {
        cout << str << endl;
    }
}

void Polar::setDecartCord(double x, double y)
{
    r = sqrt(x*x + y*y);
    p = atan(y / x);
}

pair<double, double> Polar::getCord()
{
    std::pair<double, double> point;
    point.first = r;
    point.second = p;
    return point;
}

double Polar::getR()
{
    return r;
}

double Polar::getP()
{
    return p;
}

Decart Polar::getDecartCord()
{
    Decart point(r*cos(p), r*sin(p));
    return point;
}

void Polar::print()
{
    cout << "r = " << r << ", p = " << p << '\n';
}

Decart::Decart(Polar& point)
{
    Decart tmp = point.getDecartCord();
    x = tmp.x;
    y = tmp.y;
}

void Decart::setCord(double x_, double y_)
{
    x = x_;
    y = y_;
}

void Decart::setX(double x_)
{
    x = x_;
}

void Decart::setY(double y_)
{
    y = y_;
}

void Decart::setPolarCord(double r, double p)
{
    x = r*cos(p);
    y = r*sin(p);
}

pair<double, double> Decart::getCord()
{
    pair<double, double> point;
    point.first = x;
    point.second = y;
    return point;
}

double Decart::getX()
{
    return x;
}

double Decart::getY()
{
    return y;
}

Polar Decart::getPolarCord()
{
    Polar point(sqrt(x*x + y*y), atan(y / x));
    return point;
}

void Decart::print()
{
    cout << "x = " << x << ", y = " << y << '\n';
}

int main()
{
    Polar A(1, 9);
    A.print();
    Polar B;
    B.setDecartCord(0, 3);
    B.print();
    return 0;
}
